using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Carmall.Entity;
using Carmall.IDAL;

namespace Carmall.DAL
{
	/// <summary>
	/// Attachment 的摘要说明。
	/// </summary>
	public class Attachment : BaseDAL<AttachmentInfo>, IAttachment
	{
		#region 对象实例及构造函数

		public static Attachment Instance
		{
			get
			{
				return new Attachment();
			}
		}
		public Attachment() : base("attachment","ID")
		{
		}

		#endregion

		/// <summary>
		/// 将DataReader的属性值转化为实体类的属性值，返回实体类
		/// </summary>
		/// <param name="dr">有效的DataReader对象</param>
		/// <returns>实体类对象</returns>
		protected override AttachmentInfo DataReaderToEntity(IDataReader dataReader)
		{
			AttachmentInfo attachmentInfo = new AttachmentInfo();
			SmartDataReader reader = new SmartDataReader(dataReader);
			
			attachmentInfo.ID = reader.GetInt32("ID");
            attachmentInfo.ObjectID = reader.GetInt64("ObjectID");
			attachmentInfo.ObjectType = reader.GetInt32("ObjectType");
			attachmentInfo.Title = reader.GetString("Title");
			attachmentInfo.Path = reader.GetString("Path");
			attachmentInfo.FileName = reader.GetString("FileName");
			attachmentInfo.FileType = reader.GetString("FileType");
			
			return attachmentInfo;
		}

		/// <summary>
		/// 将实体对象的属性值转化为Hashtable对应的键值
		/// </summary>
		/// <param name="obj">有效的实体对象</param>
		/// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(AttachmentInfo obj)
		{
		    AttachmentInfo info = obj as AttachmentInfo;
			Hashtable hash = new Hashtable(); 
			
			hash.Add("ID", info.ID);
            hash.Add("ObjectID", info.ObjectID);
 			hash.Add("ObjectType", info.ObjectType);
 			hash.Add("Title", info.Title);
 			hash.Add("Path", info.Path);
 			hash.Add("FileName", info.FileName);
 			hash.Add("FileType", info.FileType);
 				
			return hash;
		}

    }
}